<?php

namespace McWin\Model;
use Common\Model\CommonModel;


/*
 * 	北京赛车赔率数据.
 */

class NmgK3OpenTimeModel extends CommonModel {

	protected $trueTableName = 'c_opentime_nmg_k3';
	
	/**
	 *	生成开奖时间
	 */
	public function create_table_data(){
		// 删除旧数据.
		$sql = 'truncate c_opentime_nmg_k3'; 
		$this -> execute($sql);
		echo 'delete old data';
		
		// 生成新数据.
		// 第一次开奖和最后一次开奖, 每天73期, 09:45起每10分钟一期
		$open_time  = strtotime(date("Y-m-d") . ' 09:35:00');
		$close_time = strtotime(date("Y-m-d") . ' 22:05:00');

		$interval = 600;  // 间隔 10 分钟一期.
		$tiqian = 60;	// 开奖前 1 分钟封盘.

		$qishu = 1;
		$kaipan = $open_time;
		$kaijiang = $kaipan + $interval;
		$fengpan = $kaijiang - $tiqian;

		echo 'start creating.';
		while($kaijiang <= $close_time){
			$data['qishu'] = $qishu;
			$data['kaipan'] = date('H:i:s', $kaipan);
			$data['fengpan'] = date('H:i:s', $fengpan);
			$data['kaijiang'] = date('H:i:s', $kaijiang);
			$this -> add($data);
			echo $qishu;
			usleep(100000);

			$qishu += 1;
			$kaipan = $kaijiang;
			$kaijiang = $kaipan + $interval;
			$fengpan = $kaijiang - $tiqian;
		}

		ehco '共'. $qishu - 1 . '期';

	}

	/**
	 * [lottery_qishu description]
	 * @return [type] [description]
	 */
	function lottery_qishu(){
		$type = intval($type);
		$lottery_time = time()+1*12*3600;
		global $mysqli;
		$sql	=	"select qishu from c_opentime_".$type." where kaipan<='".date("H:i:s",$lottery_time)."' and kaijiang>='".date("H:i:s",$lottery_time)."' limit 1";
		$query	=	$mysqli->query($sql);
		$qs		=	$query->fetch_array();
		if($qs){
			//return substr(date("Ymd",$lottery_time), 2,6).BuLings($qs['qishu']);
			return date("Ymd",$lottery_time).BuLings($qs['qishu']);
		}else{
			return -1;
		}
		
	}

}
